package servlet;

import com.alibaba.fastjson.JSON;
import entity.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/detail")
public class ShowProductDetail extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();//获取浏览器会话
        Object detail = session.getAttribute("detail");

        String s1 = detail.toString();
        System.out.println(s1);
        resp.setContentType("text/json;charset=utf-8");
        String s = JSON.toJSONString(detail);
        resp.getWriter().write(s1);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
